<?php
/**
 * Description of BookDetailsDialog
 *
 * @author jordanDeroubaix
 */
mb_internal_encoding('utf-8');
mb_regex_encoding('utf-8');


include '../tools/Settings.php';
include '../tools/Sql.php';
include '../models/Member.php';
include '../models/Project.php';
include '../models/Column.php';
include_once "../tools/Log.php";

Sql::open();

if (isset($_GET['idMember'])) {

    $member = Member::getMemberById($_GET['idMember']);
    $checked = ($member->getStatut() == 1 ) ? "selected='selected'" : "";
    $checkedStatus = ($member->getIs_enabled() == 0 ) ? "checked='checked'" : "";
    
    ?>
<script>
    </script>
    <form id="user-update-form" name="user-update-form" method="POST">
        <fieldset id="user-update-form-input">
            <legend>Informations du compte</legend>
            <label for="form-update-login">Login :</label>
            <input id="form-update-login" type="text" value="<?php echo $member->getLogin() ?>" disabled="disabled" required/>
            <span id="login-update-info"></span>
            <br />
            <label for="form-update-password">Mot de passe :</label>
            <input id="form-update-password" type="password"  required/>
            <br />
            <label for="form-update-password-confirm">Confirmation Mot de passe <em>*</em></label>
            <input id="form-update-password-confirm" type="password"  required/>
            <span id="password-update-info">Laissez vide pour ne pas mofidier le mot de passe.</span>
            <label for="form-update-email">Email :</label>
            <input id="form-update-email" type="text" value="<?php echo $member->getEmail() ?>"  required/>
            <span id="mail-update-info"></span>
            <br />
            <label for="form-update-first-name">Pr&eacute;nom :</label>
            <input id="form-update-first-name" type="text" value="<?php echo $member->getFirst_name() ?>" required/>
            <br />
            <label for="form-update-last-name">Nom :</label>
            <input id="form-update-last-name" type="text" value="<?php echo $member->getLast_name() ?>" required/>
            <br />
            <label for="form-update-phone">T&eacute;l&eacute;phone :</label>
            <input id="form-update-phone" type="text" value="<?php echo $member->getPhone_number() ?>" required/>
            <br />
            <label for="form-update-address">Adresse :</label>
            <input id="form-update-address" type="text" value="<?php echo $member->getAddress() ?>"  required/>
            <br />
            <label for="form-update-city">Ville :</label>
            <input id="form-update-city" type="text" value="<?php echo $member->getCity() ?>" required/>
            <br />
            <label for="form-update-zip">Code Postal :</label>
            <input id="form-update-zip" type="text" value="<?php echo $member->getZip() ?>"  required/>
            <br />
            <label for="form-update-company">Soci&eacute;t&eacute; :</label>
            <input id="form-update-company" type="text"  value="<?php echo $member->getCompany() ?>" required/>
            <br />
            <label for="form-update-status">Statut :</label>
            <select id="form-update-status">
                <option value="0">Utilisateur</option>
                <option value="1" <?php echo $checked ?>>Administrateur global du site</option>
            </select>

            <br />
            <label for="form-update-enabled">Inactif :</label>
            <input id="form-update-enabled" <?php echo $checkedStatus ?> name="form-update-enabled" type="checkbox" value="0" required/>
            <br />
        </fieldset>
    </form>
        <?php 
}


if (isset($_GET['idProject'])) {
    $project = Project::getProjectByID($_GET['idProject']);
    $columns = Column::getColumnsProject($_GET['idProject']);
    $members = Member::getMembers();
?>
<script>
$('#form-update-list-user').multiselect({
        minWidth: 160,
        checkAllText: 'tout cocher',
        uncheckAllText: 'tout d&eacute;cocher',
        noneSelectedText: 'Utilisateurs :',
        selectedText: '# Utilisateur(s)'
    });

$('#form-update-list-admin-2').multiselect({
        minWidth: 160,
        checkAllText: 'tout cocher',
        uncheckAllText: 'tout d&eacute;cocher',
        noneSelectedText: 'Modérateurs :',
        selectedText: '# Modérateur(s)'
    });
    
    $(".chzn-select").chosen();
    $(".chzn-select-deselect").chosen({
        allow_single_deselect:true
    });
    
    $( ".project-update-del-row" ).button({
            icons: {
                primary: "ui-icon-circle-minus"
            },
            text: false
            
    });
    
    $( "#project-update-add-row" ).button({
            icons: {
                primary: "ui-icon-circle-plus"
            },
            text: false
            
    });
    
    
</script>
    <form id="project-update-form" name="project-update-form" method="POST">
                            <fieldset id="project-update-form-input">
                                <legend>Informations sur le projet</legend>
                                <label for="form-update-projectname">Nom du projet :</label>
                                <input id="form-update-projectname" type="text" value="<?php echo $project->getProjectName() ?>"  required/>
                                <span id="projectname-update-info"></span> 
                                <br />
                                
                                <label for="form-update-projectcolumn">Liste des colonnes du fichier :</label>
                                <div id="project-update-column-div" class="ui-widget">
                                    <table id="project-update-column" class="ui-widget ui-widget-content">
                                        <thead>
                                            <tr class="ui-widget-header">
                                                <th>Colonne fichier CSV</th>
                                                <th>Nom de colonne</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr id="project-update-add-tr">
                                                <td><input type="text" id="update-column_csv" name="colum_csv"/></td>
                                                <td><input type="text" id="update-column_name" name="colum_name"/></td>
                                                <td><button type="button" id="project-update-add-row">Add</button></td>
                                            </tr>
                                            <tr>
                                                <td class="csv">station_id</td>
                                                <td colspan="2">Numéro de poste</td>

                                            </tr>
                                            <tr>
                                                <td class="csv">dat</td>
                                                <td colspan="2">Date</td>
                                            </tr>
                                            <?php
                                                foreach($columns as $column){
                                                    echo "<tr>";
                                                    echo "<td>".$column->getColumnName()."</td>";
                                                    echo "<td>".$column->getColumnUsualName()."</td>";
                                                    echo "<td><button type='button' class='project-update-del-row'>Supprimer</button></td>";
                                                    echo "</tr>";
                                                }
                                            
                                            ?>
                                        </tbody>
                                    </table>
                                    <div id="delete-confirm" style="display:none;">La suppression d'une colonne entraine la suppresion <b>d&eacute;finitive</b> de toutes les donn&eacute;es de celle-ci. Etes-vous sur de vouloir supprimer cette colonne ?</div>
                                </div> 
                                <br />
                                
                                <label for="form-update-projectnblign">Nombre de points affichés :</label>
                                <input id="form-update-projectnblign" type="text" value="<?php echo $project->getProjectDefaultNBPoints() ?>"  required/>
                                <br />
                                <label for="_checkin_pic">Image du projet :</label>
                          		<span id="form-upcheckin">
								<input type="file" name="_checkin_pic" id="checkin_picUpdate">
								</span>
								<br />
								
                                <label for="form-update-list-admin-2">Liste des administrateurs : </label>
                                <select id ="form-update-list-admin-2" multiple="multiple">
                                    <?php
                                        foreach ($members as $member) {
                                            $selected = ($project->isAdmin($member->getId()) == 1) ? ' selected="selected" ' : "";
                                        echo '<option value="' . $member->getId() . '" '.$selected.'>' . $member->getLogin() . '</option>';
                                        }
                                    ?>
                                </select>
                                <br />
                                <label for="form-update-list-user">Liste des utilisateurs :</label>
                                <select id="form-update-list-user" multiple="multiple"><?php
                                    foreach ($members as $member) {
                                        $selected = ($project->isMember($member->getId()) == 1) ? ' selected="selected" ' : "";
                                        echo '<option value="' . $member->getId() . '" '.$selected.'>' . $member->getLogin() . '</option>';
                                    }
                                ?>
                                </select>
                                <br />
                                
                                <label for="form-update-default-graphe">Graphe par d&eacute;faut :</label>
                                <select id="form-update-default-graphe" class="jquery-ui-themeswitcher-trigger">
                                    <option value="<?php echo Project::GRAPHE_COURBE; ?>" <?php echo $project->getGrapheType() == Project::GRAPHE_COURBE ? "selected='selected'" : ""; ?>>Courbe</option>
                                    <option value="<?php echo Project::GRAPHE_POINT; ?>" <?php echo $project->getGrapheType() == Project::GRAPHE_POINT ? "selected='selected'" : ""; ?>>Nuage de points</option>
                                    <option value="<?php echo Project::GRAPHE_HIST0; ?>" <?php echo $project->getGrapheType() == Project::GRAPHE_HIST0 ? "selected='selected'" : ""; ?>>Histogramme</option>
                                </select>

                                <br />
                            </fieldset>

                        </form>
<?php
}


Sql::close();
?>
